#—*- coding:utf-8 -*-
#!/usr/bin/python

import json
import time

def sendWechat(self, warningNum, hash, openid, hotelName):
    contentData = {"first": {"value": ""},
                   "keyword1": {"value": "点评预警", "color": "#000"},
                   "keyword2": {"value": hotelName, "color": "#9ACD32"},
                   "keyword3": {"value": time.strftime("%Y.%m.%d %H:%M", time.localtime()), "color": "#9ACD32"},
                   "remark": {"value": """您收到{num}条预警点评""".format(num=warningNum), "color": "#000"}}
    # print json.dumps(contentData)
    self.setting.log.warning(json.dumps(contentData))
    # hash = task['ReportHash']
    send_data = {
        "token": self.setting.get("token", "wechat"),
        "appid": self.setting.get("appid", "wechat"),
        "group": self.setting.get("group", "wechat"),
        "return_url": self.setting.get("warning_message_url", "wechat") + "?hash=%s" % (hash),
        "user_id": openid,
        "template_id": self.setting.get("template_id", "wechat"),
        "data": json.dumps(contentData)
    }
    rs = wechat_message(self.setting, send_data)
    self.setting.log.warning(json.dumps(contentData) + "\n" + json.dumps(rs))
    if 'code' in rs and rs['code'] == '0000':
        status = 1
    else:
        status = 8
    return status, json.dumps(rs)
